{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "患病样本基因组数据文件总数: 7\n",
      "正常样本基因组数据文件总数: 11\n",
      "总样本基因组数据文件数: 18\n",
      "患病样本文件名 ['fix-data/AD\\\\006_S_4153.csv', 'fix-data/AD\\\\006_S_4192.csv', 'fix-data/AD\\\\018_S_4733.csv', 'fix-data/AD\\\\019_S_4252.csv', 'fix-data/AD\\\\019_S_4477.csv', 'fix-data/AD\\\\019_S_5012.csv', 'fix-data/AD\\\\019_S_5019.csv']\n",
      "正常样本文件名 ['fix-data/HC\\\\002_S_4213.csv', 'fix-data/HC\\\\002_S_4225.csv', 'fix-data/HC\\\\002_S_4262.csv', 'fix-data/HC\\\\002_S_4264.csv', 'fix-data/HC\\\\002_S_4270.csv', 'fix-data/HC\\\\006_S_4150.csv', 'fix-data/HC\\\\006_S_4357.csv', 'fix-data/HC\\\\006_S_4449.csv', 'fix-data/HC\\\\006_S_4485.csv', 'fix-data/HC\\\\012_S_4026.csv', 'fix-data/HC\\\\013_S_4579.csv']\n",
      "总样本文件名 ['006_S_4153', '006_S_4192', '018_S_4733', '019_S_4252', '019_S_4477', '019_S_5012', '019_S_5019', '002_S_4213', '002_S_4225', '002_S_4262', '002_S_4264', '002_S_4270', '006_S_4150', '006_S_4357', '006_S_4449', '006_S_4485', '012_S_4026', '013_S_4579']\n"
     ]
    }
   ],
   "source": [
    "import glob, os\n",
    "from os import getcwd\n",
    "from os import listdir\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "ad_files_num=len(os.listdir('fix-data/AD'))\n",
    "hc_files_num=len(os.listdir('fix-data/HC'))\n",
    "print(\"患病样本基因组数据文件总数:\",ad_files_num)\n",
    "print(\"正常样本基因组数据文件总数:\",hc_files_num)\n",
    "files_num=ad_files_num+hc_files_num\n",
    "print(\"总样本基因组数据文件数:\",files_num) \n",
    "adfiles = glob.glob(os.path.join('fix-data/AD/*.csv'))\n",
    "hcfiles = glob.glob(os.path.join('fix-data/HC/*.csv'))\n",
    "print (\"患病样本文件名\",adfiles)\n",
    "print (\"正常样本文件名\",hcfiles)\n",
    "allfiles = adfiles+hcfiles\n",
    "allfiles_name=[]\n",
    "for filepath in allfiles:\n",
    "    allfiles_name.append(filepath.split('.')[0].split('\\\\')[1])\n",
    "print (\"总样本文件名\",allfiles_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>家系ID</th>\n",
       "      <th>样本ID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>006_S_4153</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>006_S_4192</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>018_S_4733</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>019_S_4252</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>019_S_4477</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   家系ID        样本ID\n",
       "0     0  006_S_4153\n",
       "1     1  006_S_4192\n",
       "2     2  018_S_4733\n",
       "3     3  019_S_4252\n",
       "4     4  019_S_4477"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_ped = pd.DataFrame({'家系ID': pd.Series(range(files_num), index=list(range(files_num)), dtype='int32')})\n",
    "allfiles_name = pd.Series(allfiles_name)\n",
    "df_ped['样本ID']= allfiles_name.values\n",
    "df_ped.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>家系ID</th>\n",
       "      <th>样本ID</th>\n",
       "      <th>父ID</th>\n",
       "      <th>母ID</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>006_S_4153</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>006_S_4192</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>018_S_4733</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>019_S_4252</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>019_S_4477</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   家系ID        样本ID  父ID  母ID\n",
       "0     0  006_S_4153    0    0\n",
       "1     1  006_S_4192    0    0\n",
       "2     2  018_S_4733    0    0\n",
       "3     3  019_S_4252    0    0\n",
       "4     4  019_S_4477    0    0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_ped['父ID']= 0\n",
    "df_ped['母ID']= 0\n",
    "df_ped.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Image Data ID</th>\n",
       "      <th>Subject</th>\n",
       "      <th>Group</th>\n",
       "      <th>Sex</th>\n",
       "      <th>Age</th>\n",
       "      <th>Visit</th>\n",
       "      <th>Modality</th>\n",
       "      <th>Description</th>\n",
       "      <th>Type</th>\n",
       "      <th>Acq Date</th>\n",
       "      <th>Format</th>\n",
       "      <th>Downloaded</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>I248516</td>\n",
       "      <td>006_S_4153</td>\n",
       "      <td>AD</td>\n",
       "      <td>M</td>\n",
       "      <td>79</td>\n",
       "      <td>22</td>\n",
       "      <td>fMRI</td>\n",
       "      <td>Resting State fMRI</td>\n",
       "      <td>Original</td>\n",
       "      <td>8/03/2011</td>\n",
       "      <td>DCM</td>\n",
       "      <td>12/04/2020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>I258605</td>\n",
       "      <td>006_S_4192</td>\n",
       "      <td>AD</td>\n",
       "      <td>M</td>\n",
       "      <td>82</td>\n",
       "      <td>22</td>\n",
       "      <td>fMRI</td>\n",
       "      <td>Resting State fMRI</td>\n",
       "      <td>Original</td>\n",
       "      <td>9/27/2011</td>\n",
       "      <td>DCM</td>\n",
       "      <td>12/04/2020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>I306073</td>\n",
       "      <td>018_S_4733</td>\n",
       "      <td>AD</td>\n",
       "      <td>M</td>\n",
       "      <td>75</td>\n",
       "      <td>22</td>\n",
       "      <td>fMRI</td>\n",
       "      <td>Resting State fMRI</td>\n",
       "      <td>Original</td>\n",
       "      <td>5/23/2012</td>\n",
       "      <td>DCM</td>\n",
       "      <td>12/04/2020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>I258955</td>\n",
       "      <td>019_S_4252</td>\n",
       "      <td>AD</td>\n",
       "      <td>F</td>\n",
       "      <td>87</td>\n",
       "      <td>22</td>\n",
       "      <td>fMRI</td>\n",
       "      <td>Resting State fMRI</td>\n",
       "      <td>Original</td>\n",
       "      <td>9/28/2011</td>\n",
       "      <td>DCM</td>\n",
       "      <td>12/04/2020</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>I280778</td>\n",
       "      <td>019_S_4477</td>\n",
       "      <td>AD</td>\n",
       "      <td>F</td>\n",
       "      <td>82</td>\n",
       "      <td>22</td>\n",
       "      <td>fMRI</td>\n",
       "      <td>Resting State fMRI</td>\n",
       "      <td>Original</td>\n",
       "      <td>1/25/2012</td>\n",
       "      <td>DCM</td>\n",
       "      <td>12/04/2020</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Image Data ID     Subject Group Sex  Age  Visit Modality  \\\n",
       "0       I248516  006_S_4153    AD   M   79     22     fMRI   \n",
       "1       I258605  006_S_4192    AD   M   82     22     fMRI   \n",
       "2       I306073  018_S_4733    AD   M   75     22     fMRI   \n",
       "3       I258955  019_S_4252    AD   F   87     22     fMRI   \n",
       "4       I280778  019_S_4477    AD   F   82     22     fMRI   \n",
       "\n",
       "          Description      Type   Acq Date Format  Downloaded  \n",
       "0  Resting State fMRI  Original  8/03/2011    DCM  12/04/2020  \n",
       "1  Resting State fMRI  Original  9/27/2011    DCM  12/04/2020  \n",
       "2  Resting State fMRI  Original  5/23/2012    DCM  12/04/2020  \n",
       "3  Resting State fMRI  Original  9/28/2011    DCM  12/04/2020  \n",
       "4  Resting State fMRI  Original  1/25/2012    DCM  12/04/2020  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_sex = pd.read_csv(\"fix-data/sex.csv\",header=0,index_col=False)#读取性别文件从0行开始算，重新设置一列成为index值\n",
    "df_sex.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>家系ID</th>\n",
       "      <th>样本ID</th>\n",
       "      <th>父ID</th>\n",
       "      <th>母ID</th>\n",
       "      <th>性别</th>\n",
       "      <th>表型</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>006_S_4153</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>006_S_4192</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>018_S_4733</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>019_S_4252</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>019_S_4477</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   家系ID        样本ID  父ID  母ID  性别  表型\n",
       "0     0  006_S_4153    0    0   1   2\n",
       "1     1  006_S_4192    0    0   1   2\n",
       "2     2  018_S_4733    0    0   1   2\n",
       "3     3  019_S_4252    0    0   2   2\n",
       "4     4  019_S_4477    0    0   2   2"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cllumn_name='Sex'\n",
    "pan_sexm = (df_sex[cllumn_name]=='M')\n",
    "pan_sexf = (df_sex[cllumn_name]=='F')\n",
    "df_ped.loc[pan_sexm,'性别'] = 1\n",
    "df_ped.loc[pan_sexf,'性别'] = 2\n",
    "df_ped['表型']=np.array([2] * ad_files_num+[1] * hc_files_num, dtype='int32')\n",
    "\n",
    "df_ped.loc[:, \"性别\"] = df_ped[\"性别\"].astype('int32')\n",
    "df_ped.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>SNP Name</th>\n",
       "      <th>Allele1 - Forward</th>\n",
       "      <th>Allele2 - Forward</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>rs1000000</td>\n",
       "      <td>T</td>\n",
       "      <td>C</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>rs1000002</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>rs10000023</td>\n",
       "      <td>T</td>\n",
       "      <td>T</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>rs1000003</td>\n",
       "      <td>A</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>rs10000030</td>\n",
       "      <td>G</td>\n",
       "      <td>G</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     SNP Name Allele1 - Forward Allele2 - Forward\n",
       "0   rs1000000                 T                 C\n",
       "1   rs1000002                 A                 G\n",
       "2  rs10000023                 T                 T\n",
       "3   rs1000003                 A                 G\n",
       "4  rs10000030                 G                 G"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df =  pd.read_csv(\"fix-data/AD/006_S_4153.csv\",header=0,index_col=False)#从0行开始算，重新设置一列成为index值\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>家系ID</th>\n",
       "      <th>样本ID</th>\n",
       "      <th>父ID</th>\n",
       "      <th>母ID</th>\n",
       "      <th>性别</th>\n",
       "      <th>表型</th>\n",
       "      <th>index</th>\n",
       "      <th>snp1</th>\n",
       "      <th>snp2</th>\n",
       "      <th>snp3</th>\n",
       "      <th>...</th>\n",
       "      <th>snp730388</th>\n",
       "      <th>snp730389</th>\n",
       "      <th>snp730390</th>\n",
       "      <th>snp730391</th>\n",
       "      <th>snp730392</th>\n",
       "      <th>snp730393</th>\n",
       "      <th>snp730394</th>\n",
       "      <th>snp730395</th>\n",
       "      <th>snp730396</th>\n",
       "      <th>snp730397</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>006_S_4153</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>snp</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 730404 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   家系ID        样本ID  父ID  母ID  性别  表型 index snp1 snp2 snp3  ... snp730388  \\\n",
       "0     0  006_S_4153    0    0   1   2   snp  T C  A G  T T  ...       A A   \n",
       "\n",
       "  snp730389 snp730390 snp730391 snp730392 snp730393 snp730394 snp730395  \\\n",
       "0       C C       G G       C C       A G       G G       C C       T T   \n",
       "\n",
       "  snp730396 snp730397  \n",
       "0       C C       G G  \n",
       "\n",
       "[1 rows x 730404 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['snp']=df['Allele1 - Forward'].str.cat(df['Allele2 - Forward'],sep=' ')#拼接结果不添加\n",
    "df_new = pd.DataFrame(df['snp'])\n",
    "df_new['columns']= 'snp'\n",
    "df_new['num']=df.index+1\n",
    "df_new['columns_num']=df_new['columns'].str.cat(df_new['num'].astype('str'),sep='')\n",
    "df_new=df_new[df_new.index<730397]\n",
    "del df_new['columns']\n",
    "del df_new['num']\n",
    "df_column=df_new.set_index('columns_num').T\n",
    "df_column_new=df_column.reset_index()\n",
    "df_column_new['家系ID']=0\n",
    "res= pd.merge(df_ped,df_column_new,on=['家系ID'])\n",
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "res.to_csv(\"fix-data/ped.csv\", index = False, header=None,sep=' ', encoding='utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "处理家系完成，编号： 0\n",
      "处理家系完成，编号： 1\n",
      "处理家系完成，编号： 2\n",
      "处理家系完成，编号： 3\n",
      "处理家系完成，编号： 4\n",
      "处理家系完成，编号： 5\n",
      "处理家系完成，编号： 6\n",
      "处理家系完成，编号： 7\n",
      "处理家系完成，编号： 8\n",
      "处理家系完成，编号： 9\n",
      "处理家系完成，编号： 10\n",
      "处理家系完成，编号： 11\n",
      "处理家系完成，编号： 12\n",
      "处理家系完成，编号： 13\n",
      "处理家系完成，编号： 14\n",
      "处理家系完成，编号： 15\n",
      "处理家系完成，编号： 16\n",
      "处理家系完成，编号： 17\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>家系ID</th>\n",
       "      <th>index</th>\n",
       "      <th>snp1</th>\n",
       "      <th>snp2</th>\n",
       "      <th>snp3</th>\n",
       "      <th>snp4</th>\n",
       "      <th>snp5</th>\n",
       "      <th>snp6</th>\n",
       "      <th>snp7</th>\n",
       "      <th>snp8</th>\n",
       "      <th>...</th>\n",
       "      <th>snp730388</th>\n",
       "      <th>snp730389</th>\n",
       "      <th>snp730390</th>\n",
       "      <th>snp730391</th>\n",
       "      <th>snp730392</th>\n",
       "      <th>snp730393</th>\n",
       "      <th>snp730394</th>\n",
       "      <th>snp730395</th>\n",
       "      <th>snp730396</th>\n",
       "      <th>snp730397</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>snp</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>3</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>A A</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>4</td>\n",
       "      <td>snp</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T C</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>T T</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>T G</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>7</td>\n",
       "      <td>snp</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>8</td>\n",
       "      <td>snp</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T G</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11</td>\n",
       "      <td>snp</td>\n",
       "      <td>T T</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>12</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>13</td>\n",
       "      <td>snp</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>14</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T G</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>16</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17</td>\n",
       "      <td>snp</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T G</td>\n",
       "      <td>C C</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>18 rows × 730399 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   家系ID index snp1 snp2 snp3 snp4 snp5 snp6 snp7 snp8  ... snp730388  \\\n",
       "0     0   snp  T C  A G  T T  A G  G G  G G  T T  C C  ...       A A   \n",
       "0     1   snp  C C  G G  T T  A G  G G  A A  T T  C C  ...       A G   \n",
       "0     2   snp  C C  A G  G G  A A  G G  G G  T T  C C  ...       A A   \n",
       "0     3   snp  C C  G G  T G  A A  A G  A A  T T  C C  ...       A G   \n",
       "0     4   snp  T C  A G  T G  A A  G G  G G  T T  C C  ...       A A   \n",
       "0     5   snp  C C  A G  T G  A A  A G  G G  T T  C C  ...       A A   \n",
       "0     6   snp  C C  A A  T T  A A  G G  A A  T G  C C  ...       A A   \n",
       "0     7   snp  T C  A G  T T  A A  G G  G G  T T  C C  ...       A A   \n",
       "0     8   snp  T C  A G  T G  A A  G G  G G  T G  C C  ...       A A   \n",
       "0     9   snp  C C  A G  T T  A A  A G  G G  T T  C C  ...       A G   \n",
       "0    10   snp  C C  G G  T G  A A  G G  A G  T T  C C  ...       A G   \n",
       "0    11   snp  T T  G G  G G  A A  A G  G G  T T  C C  ...       A G   \n",
       "0    12   snp  C C  A G  T T  A G  G G  A G  T G  C C  ...       A A   \n",
       "0    13   snp  T C  A G  T G  A A  G G  G G  T T  C C  ...       A A   \n",
       "0    14   snp  C C  A A  T G  A A  G G  G G  T T  C C  ...       A A   \n",
       "0    15   snp  C C  A A  T T  A G  G G  G G  T G  C C  ...       A G   \n",
       "0    16   snp  C C  A G  T T  A G  G G  A G  T T  C C  ...       A G   \n",
       "0    17   snp  C C  G G  T T  A G  G G  G G  T G  C C  ...       A A   \n",
       "\n",
       "  snp730389 snp730390 snp730391 snp730392 snp730393 snp730394 snp730395  \\\n",
       "0       C C       G G       C C       A G       G G       C C       T T   \n",
       "0       C C       G G       A A       A G       G G       C C       T T   \n",
       "0       T C       G G       C C       A A       A G       T C       T T   \n",
       "0       C C       G G       C C       A G       A G       T C       T T   \n",
       "0       T C       G G       A C       A G       G G       C C       T C   \n",
       "0       C C       G G       A C       A A       G G       C C       T T   \n",
       "0       T C       G G       C C       A G       G G       C C       T T   \n",
       "0       T C       G G       C C       A G       A G       C C       T T   \n",
       "0       C C       G G       C C       A A       G G       C C       T T   \n",
       "0       C C       G G       A C       A G       G G       C C       T T   \n",
       "0       T C       G G       A C       A G       G G       T C       T T   \n",
       "0       T C       G G       C C       A G       G G       T C       T T   \n",
       "0       C C       G G       A C       A G       G G       C C       T T   \n",
       "0       T C       G G       A C       A A       G G       C C       T T   \n",
       "0       T C       G G       A C       A A       G G       T C       T T   \n",
       "0       T C       G G       A A       A G       G G       C C       T T   \n",
       "0       T C       G G       C C       G G       G G       T C       T T   \n",
       "0       T C       G G       C C       A A       A G       C C       T T   \n",
       "\n",
       "  snp730396 snp730397  \n",
       "0       C C       G G  \n",
       "0       C C       G G  \n",
       "0       C C       G G  \n",
       "0       C C       G G  \n",
       "0       C C       G G  \n",
       "0       T C       G G  \n",
       "0       C C       G G  \n",
       "0       C C       G G  \n",
       "0       T C       G G  \n",
       "0       C C       G G  \n",
       "0       C C       G G  \n",
       "0       C C       A G  \n",
       "0       T C       G G  \n",
       "0       C C       G G  \n",
       "0       C C       G G  \n",
       "0       T C       G G  \n",
       "0       C C       G G  \n",
       "0       T C       G G  \n",
       "\n",
       "[18 rows x 730399 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res=pd.DataFrame({'家系ID': range(0)})\n",
    "for filepath in allfiles:\n",
    "    df =  pd.read_csv(filepath,header=0,index_col=False)#从0行开始算，重新设置一列成为index值\n",
    "    df['snp']=df['Allele1 - Forward'].str.cat(df['Allele2 - Forward'],sep=' ')#拼接结果不添加\n",
    "    df_new = pd.DataFrame(df['snp'])\n",
    "    df_new['columns']= 'snp'\n",
    "    df_new['num']=df.index+1\n",
    "    df_new['columns_num']=df_new['columns'].str.cat(df_new['num'].astype('str'),sep='')\n",
    "    df_new=df_new[df_new.index<730397]\n",
    "    del df_new['columns']\n",
    "    del df_new['num']\n",
    "    df_column=df_new.set_index('columns_num').T\n",
    "    df_column_new=df_column.reset_index()\n",
    "    df_column_new['家系ID']=allfiles.index(filepath)\n",
    "    print(\"处理家系完成，编号：\",allfiles.index(filepath))\n",
    "    res=res.append(df_column_new)\n",
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>家系ID</th>\n",
       "      <th>样本ID</th>\n",
       "      <th>父ID</th>\n",
       "      <th>母ID</th>\n",
       "      <th>性别</th>\n",
       "      <th>表型</th>\n",
       "      <th>snp1</th>\n",
       "      <th>snp2</th>\n",
       "      <th>snp3</th>\n",
       "      <th>snp4</th>\n",
       "      <th>...</th>\n",
       "      <th>snp730388</th>\n",
       "      <th>snp730389</th>\n",
       "      <th>snp730390</th>\n",
       "      <th>snp730391</th>\n",
       "      <th>snp730392</th>\n",
       "      <th>snp730393</th>\n",
       "      <th>snp730394</th>\n",
       "      <th>snp730395</th>\n",
       "      <th>snp730396</th>\n",
       "      <th>snp730397</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>006_S_4153</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>006_S_4192</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>018_S_4733</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>019_S_4252</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>019_S_4477</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T C</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>019_S_5012</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>019_S_5019</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>T T</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>7</td>\n",
       "      <td>002_S_4213</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>8</td>\n",
       "      <td>002_S_4225</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>9</td>\n",
       "      <td>002_S_4262</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>10</td>\n",
       "      <td>002_S_4264</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>11</td>\n",
       "      <td>002_S_4270</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>T T</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>12</td>\n",
       "      <td>006_S_4150</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>13</td>\n",
       "      <td>006_S_4357</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>T C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>14</td>\n",
       "      <td>006_S_4449</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>T G</td>\n",
       "      <td>A A</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A C</td>\n",
       "      <td>A A</td>\n",
       "      <td>G G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>15</td>\n",
       "      <td>006_S_4485</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>16</td>\n",
       "      <td>012_S_4026</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>C C</td>\n",
       "      <td>A G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>...</td>\n",
       "      <td>A G</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>G G</td>\n",
       "      <td>T C</td>\n",
       "      <td>T T</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>17</td>\n",
       "      <td>013_S_4579</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>C C</td>\n",
       "      <td>G G</td>\n",
       "      <td>T T</td>\n",
       "      <td>A G</td>\n",
       "      <td>...</td>\n",
       "      <td>A A</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "      <td>C C</td>\n",
       "      <td>A A</td>\n",
       "      <td>A G</td>\n",
       "      <td>C C</td>\n",
       "      <td>T T</td>\n",
       "      <td>T C</td>\n",
       "      <td>G G</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>18 rows × 730403 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    家系ID        样本ID  父ID  母ID  性别  表型 snp1 snp2 snp3 snp4  ... snp730388  \\\n",
       "0      0  006_S_4153    0    0   1   2  T C  A G  T T  A G  ...       A A   \n",
       "1      1  006_S_4192    0    0   1   2  C C  G G  T T  A G  ...       A G   \n",
       "2      2  018_S_4733    0    0   1   2  C C  A G  G G  A A  ...       A A   \n",
       "3      3  019_S_4252    0    0   2   2  C C  G G  T G  A A  ...       A G   \n",
       "4      4  019_S_4477    0    0   2   2  T C  A G  T G  A A  ...       A A   \n",
       "5      5  019_S_5012    0    0   1   2  C C  A G  T G  A A  ...       A A   \n",
       "6      6  019_S_5019    0    0   2   2  C C  A A  T T  A A  ...       A A   \n",
       "7      7  002_S_4213    0    0   2   1  T C  A G  T T  A A  ...       A A   \n",
       "8      8  002_S_4225    0    0   1   1  T C  A G  T G  A A  ...       A A   \n",
       "9      9  002_S_4262    0    0   2   1  C C  A G  T T  A A  ...       A G   \n",
       "10    10  002_S_4264    0    0   2   1  C C  G G  T G  A A  ...       A G   \n",
       "11    11  002_S_4270    0    0   2   1  T T  G G  G G  A A  ...       A G   \n",
       "12    12  006_S_4150    0    0   1   1  C C  A G  T T  A G  ...       A A   \n",
       "13    13  006_S_4357    0    0   2   1  T C  A G  T G  A A  ...       A A   \n",
       "14    14  006_S_4449    0    0   2   1  C C  A A  T G  A A  ...       A A   \n",
       "15    15  006_S_4485    0    0   1   1  C C  A A  T T  A G  ...       A G   \n",
       "16    16  012_S_4026    0    0   1   1  C C  A G  T T  A G  ...       A G   \n",
       "17    17  013_S_4579    0    0   1   1  C C  G G  T T  A G  ...       A A   \n",
       "\n",
       "   snp730389 snp730390 snp730391 snp730392 snp730393 snp730394 snp730395  \\\n",
       "0        C C       G G       C C       A G       G G       C C       T T   \n",
       "1        C C       G G       A A       A G       G G       C C       T T   \n",
       "2        T C       G G       C C       A A       A G       T C       T T   \n",
       "3        C C       G G       C C       A G       A G       T C       T T   \n",
       "4        T C       G G       A C       A G       G G       C C       T C   \n",
       "5        C C       G G       A C       A A       G G       C C       T T   \n",
       "6        T C       G G       C C       A G       G G       C C       T T   \n",
       "7        T C       G G       C C       A G       A G       C C       T T   \n",
       "8        C C       G G       C C       A A       G G       C C       T T   \n",
       "9        C C       G G       A C       A G       G G       C C       T T   \n",
       "10       T C       G G       A C       A G       G G       T C       T T   \n",
       "11       T C       G G       C C       A G       G G       T C       T T   \n",
       "12       C C       G G       A C       A G       G G       C C       T T   \n",
       "13       T C       G G       A C       A A       G G       C C       T T   \n",
       "14       T C       G G       A C       A A       G G       T C       T T   \n",
       "15       T C       G G       A A       A G       G G       C C       T T   \n",
       "16       T C       G G       C C       G G       G G       T C       T T   \n",
       "17       T C       G G       C C       A A       A G       C C       T T   \n",
       "\n",
       "   snp730396 snp730397  \n",
       "0        C C       G G  \n",
       "1        C C       G G  \n",
       "2        C C       G G  \n",
       "3        C C       G G  \n",
       "4        C C       G G  \n",
       "5        T C       G G  \n",
       "6        C C       G G  \n",
       "7        C C       G G  \n",
       "8        T C       G G  \n",
       "9        C C       G G  \n",
       "10       C C       G G  \n",
       "11       C C       A G  \n",
       "12       T C       G G  \n",
       "13       C C       G G  \n",
       "14       C C       G G  \n",
       "15       T C       G G  \n",
       "16       C C       G G  \n",
       "17       T C       G G  \n",
       "\n",
       "[18 rows x 730403 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_ped_out= pd.merge(df_ped,res,on=['家系ID'])\n",
    "del df_ped_out['index']\n",
    "df_ped_out"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 保存生成的ped文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "#df_ped_out.replace('- -', '0 0',inplace=True)\n",
    "df_ped_out.to_csv(\"fix-data/ped.csv\", index = False,header=None,sep=',', encoding='utf-8')#保存时去除表头"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 行列转换演示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = pd.DataFrame({'key': ['b', 'b', 'a', 'c', 'a', 'a', 'b'],\n",
    "                    'data1': range(7)})\n",
    "df1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df1.set_index('key').T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
